<template>
  <div class="app-container">
    <el-row :gutter="20">
      <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
        <!--资讯数据-->
        <pane size="84">
          <el-col>
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
              <el-form-item label="公司名称" prop="companyName">
                <el-input v-model="queryParams.companyName" placeholder="请输入公司名称" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="联系人" prop="contact">
                <el-input v-model="queryParams.contact" placeholder="请输入联系人" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>

            <el-row :gutter="10" class="mb8">
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
            </el-row>

            <el-table v-loading="loading" :data="messageList">
              <el-table-column label="公司名称" align="center" key="companyName" prop="companyName" v-if="columns.companyName.visible" :show-overflow-tooltip="true" />
              <el-table-column label="联系人" align="center" key="contact" prop="contact" v-if="columns.contact.visible" :show-overflow-tooltip="true" />
              <el-table-column label="联系电话" align="center" key="phone" prop="phone" v-if="columns.phone.visible" :show-overflow-tooltip="true" />
              <el-table-column label="提交时间" align="center" prop="createTime" v-if="columns.createTime.visible" width="160">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
                <template slot-scope="scope" v-if="scope.row.userId !== 1">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']">查看</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </el-col>
        </pane>
      </splitpanes>
    </el-row>

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="70%" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="companyName">
              <el-input v-model="form.companyName" placeholder="公司名称" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contact">
              <el-input v-model="form.contact" placeholder="联系人" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="联系电话" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系邮箱" prop="email">
              <el-input v-model="form.email" placeholder="联系邮箱"readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="咨询信息" prop="content">
              <el-input v-model="form.content" type="textarea" placeholder="咨询信息" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关  闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>



<script>
import {listMessage, getMessage} from "@/api/system/message"
import {getSite} from "@/utils/auth"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"

export default {
  name: "Message",
  components: { Splitpanes, Pane },

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      messageList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        tenantId: getSite(),
        pageNum: 1,
        pageSize: 10,
      },
      // 列信息
      columns: {
        companyName: { label: '公司名称', visible: true },
        contact: { label: '联系人', visible: true },
        phone: { label: '联系电话', visible: true },
        createTime: { label: '提交时间', visible: true }
      },
    }
  },
  created() {
    this.getList()
  },
  computed: {
  },
  methods: {
    /** 查询资讯列表 */
    getList() {
      this.loading = true
      listMessage(this.queryParams).then(response => {
          this.messageList = response.rows
          this.total = response.total
          this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {}
      this.resetForm("form")
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id
      getMessage(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "查看业务咨询"
      })
    }
  }
}
</script>
